package id.web.faisalabdillah.xtimesheet.services.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import id.web.faisalabdillah.xtimesheet.dao.IFileStorageDao;
import id.web.faisalabdillah.xtimesheet.domain.FileStorage;
import id.web.faisalabdillah.xtimesheet.services.IFileStorageService;

@Service
@Transactional(readOnly = true)
public class FileStorageServiceImpl implements IFileStorageService {
	@Autowired
	private IFileStorageDao fileStorageDao;

	@Override
	@Transactional(readOnly = false)
	public boolean insert(FileStorage storage) {
		try {
			fileStorageDao.insert(storage);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	@Override
	@Transactional(readOnly = false)
	public boolean update(FileStorage storage) {
		try {
			fileStorageDao.update(storage);
		} catch (Exception e) {
			return false;
		}
		return true;
	}

	@Override
	@Transactional(readOnly = false)
	public boolean remove(long id) {
		try {
			fileStorageDao.remove(findById(id));
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	@Override
	public FileStorage findByCodename(String codename) {
		return fileStorageDao.findByCodename(codename);
	}

	@Override
	public FileStorage findById(long id) {
		return fileStorageDao.findById(id);
	}

	@Override
	public List<FileStorage> listAll() {
		return fileStorageDao.listAll();
	}

	@Override
	public List<FileStorage> listPaging(int first, int max) {
		return fileStorageDao.listPaging(first, max);
	}

	@Override
	public int sizeAll() {
		return fileStorageDao.sizeAll();
	}

}
